import { Modal } from 'ant-design-vue'
import { ref } from 'vue'

export const useDelList = (props) => {

  const delIds = ref([])

  const del = (id) => {
    Modal.confirm({
      title: '确定要删除吗',
      async onOk() {
        // 获取要删除的id
        const ids = id ? [id] : delIds.value

        // 调用删除接口
        await props.api(ids)
        // 重置列表数据

        props.paginationParams.value = {
          ...props.paginationParams.value,
          page: 1
        }

        // 清空删除数组
        delIds.value = []

      },
    });
  }
  
  return {
    del,
    delIds
  }
}